package com.xc.hotelmgr.order.common.utils;

import com.alibaba.fastjson.JSON;
import com.xc.hotelmgr.order.modules.ali.to.common.DailyInfo;
import com.xc.hotelmgr.order.modules.ali.to.validaterq.response.InventoryPrice;
import com.xc.hotelmgr.order.modules.ali.to.validaterq.response.ValidateRQResult;

import java.util.List;

public class GeneValidateVQResponse {
    /**
     * 生成下单前校验返回信息
     * @param sucess
     * @param dailyInfos
     * @param createOrderValidateKey
     * @return
     */
    public static ValidateRQResult gene(Boolean sucess, List<DailyInfo> dailyInfos, String createOrderValidateKey){
        ValidateRQResult validateRQResponse = new ValidateRQResult();
        //构建InventoryPrice
        String inventoryPrice = "[";
        InventoryPrice inventoryPriceResponse = null;
        for (DailyInfo dailyInfo : dailyInfos){
            inventoryPriceResponse = new InventoryPrice();
            inventoryPriceResponse.setDate(dailyInfo.getDay());
            inventoryPriceResponse.setPrice(dailyInfo.getPrice().toString());
            inventoryPriceResponse.setQuota("3");
            inventoryPrice = inventoryPrice + JSON.toJSON(inventoryPriceResponse) + ",";
        }
        inventoryPrice = inventoryPrice.replaceAll("\\,$","]");
        if(sucess){
            validateRQResponse.setMessage("验证成功");
            validateRQResponse.setResultCode("0");
        }else {
            validateRQResponse.setMessage("验证失败");
            validateRQResponse.setResultCode("-1");
        }
        validateRQResponse.setCreateOrderValidateKey(createOrderValidateKey);
        validateRQResponse.setInventoryPrice(inventoryPrice);
        return validateRQResponse;
    }

}
